package com.hzw.code.common.utils;

/**
 * 通用返回枚举
 *
 * @author: 胡汉三
 * @date: 2020/5/18 10:00
 */
public enum ResultCodeEnum {

	SUCCESS(0, "操作成功"),

	HTTP_404(404, "请求地址不存在"),

	ERROR_DEFAULT(5000, "系统繁忙，请稍后再试"),
	ERROR_UNKNOWN(5001, "服务器发生未知错误"),
	ERROR_EXECPTION(5002, "全局程序异常错误"),
	ERROR_SERVICE_UNAVAILABLE(5003, "无效服务"),
	ERROR_NOT_FOUND(5004, "请求页面或接口不存在"),
	ERROR_HTTP_METHOD(5005, "不支持该请求方式"),
	ERROR_SYSTEM(5006, "系统错误"),

	// 数据输入相关
	DATA_INPUT_ERROR(1001, "参数错误"),
	DATA_INPUT_EMPTY(1002, "参数不能为空"),
	DATA_INPUT_TYPE_ERROR(1003, "参数类型错误"),
	DATA_INPUT_OVERRUN(1004, "数据超过允许范围"),
	DATA_EXISTS(1005, "数据已存在"),
	DATA_INVALID(1006, "数据无效"),
	DATA_DISABLE(1007, "数据已被冻结"),

	// 数据库相关，返回restful标准错误码均为服务器内部错误500
	DATABASE_BASE_ERROR(2000, "操作失败"),
	DATABASE_QUERY_ERROR(2001, "查询失败"),
	DATABASE_INSERT_ERROR(2002, "新增失败"),
	DATABASE_UPDATE_ERROR(2003, "更新失败"),
	DATABASE_DELETE_ERROR(2004, "删除失败"),
	DATABASE_NODATA(2005, "数据不存在"),
	DATABASE_TOO_MANY(2006, "存在多条记录"),

	DATA_API_DEFAULT(2100, "操作失败"),
	DATA_API_INVALID_STATEMENT(2101, "无效的操作方法"),

	TOKEN_MISS(1201, "缺少token"),
	TOKEN_INVALID(1202, "token无效"),

	ACCOUNT_NOT_EXIST(1301, "账号不存在"),
	ACCOUNT_DISABLED(1302, "账号已冻结"),
	ACCOUNT_PASSWORD_WRONG(1303, "密码错误"),
	ACCOUNT_LOGIN_OVER(1304, "同时登录次数超过限制"),
	ACCOUNT_ERROR_OVER(1305, "登录错误次数超过限制"),
	ORG_INVALID(1306, "无效机构"),
	ORG_DISABLED(1307, "机构已冻结"),

	UNAUTH(4001, "未授权访问"),
	UNLOGIN(4002, "未登录"),
	FORBID(4003, "禁止操作"),
	NOAUTH(4004, "没有权限"),
	AUTH_LOWER(4005, "权限不足"),
	LOGIN_FAIL(4006, "登录失败");

	private Integer value;
	private String desc;

	/**
	 * httpStatus不传默认为请求错误
	 * @param value
	 * @param desc
	 */
	private ResultCodeEnum(Integer value, String desc) {
		this.value = value;
		this.desc = desc;
	}

	private ResultCodeEnum(Integer value, String desc, int httpStatus) {
		this.value = value;
		this.desc = desc;
	}

	/**
	 * 获取枚举值
	 * @return
	 */
	public Integer getValue() {
		return value;
	}

	/**
	 * 获取枚举描述
	 * @return
	 */
	public String getDesc() {
		return desc;
	}

    public static String getDesc(String value) {
        ResultCodeEnum[] var1 = values();
        int var2 = var1.length;

        for(int var3 = 0; var3 < var2; ++var3) {
            ResultCodeEnum c = var1[var3];
            if (c.getValue().equals(value)) {
                return c.desc;
            }
        }
        return null;
    }
}
